<template>
  <div class="commentWrapper">
    <div class="info">
      <img
        v-if="commentData.user.head_img"
        :src="$axios.defaults.baseURL+commentData.user.head_img"
        alt
        class="avatar"
      />
      <img v-else src="../assets/01.jpg" alt class="avatar" />
      <div class="name">
        {{commentData.user.nickname}}
        <div class="date">{{commentData.create_date.split("T")[0]}}</div>
      </div>

      <div class="huifu" @click="reply">回复</div>
    </div>
    <div class="mainContent">{{commentData.content }}</div>
    <Parent :parentData="commentData.parent" v-if="commentData.parent">{{commentData.content}}</Parent>
  </div>
</template>

<script>
import Parent from "../components/Parent";
// 引入事件总线
import Bus from "../util/Bus";

export default {
  components: {
    Parent,
  },
  props: ["commentData"],
  methods: {
    reply() {
      // 通知总线(vue实例) 顺带要的参数
      Bus.$emit("reply", this.commentData.id);
    },
  },
};
</script>

<style lang="less" scoped>
.commentWrapper {
  border-bottom: 1px solid red;
  padding: 10/360 * 100vw;
  .info {
    display: flex;
    align-items: center;
    .avatar {
      width: 36/360 * 100vw;
      height: 36/360 * 100vw;
      object-fit: cover;
      border-radius: 50%;
    }
    .name {
      flex: 1;
      padding-left: 10/360 * 100vw;
      font-size: 16/360 * 100vw;
      .date {
        margin-top: 5/360 * 100vw;
        font-size: 12/360 * 100vw;
        color: #bbb;
      }
    }

    .huifu {
      font-size: 14/360 * 100vw;
      color: #888;
    }
  }
  .mainContent {
    padding: 10/360 * 100vw 0;
    color: #444;
  }
}
</style>